<?php

/**
 * 附件上传
 */
namespace Asset\Controller;
use Common\Controller\AdminbaseController;
class AssetController extends AdminbaseController {


    function _initialize() {
    	$adminid=sp_get_current_admin_id();
    	$userid=sp_get_current_userid();
    	if(empty($adminid) && empty($userid)){
    		exit("非法上传！");
    	}
    }

    /**
     * swfupload 上传 
     */
    public function swfupload() {
        if (IS_POST) {
			$savepath=date('Ymd').'/';
            //上传处理类
            $config=array(
            		'rootPath' => './'.C("UPLOADPATH"),
            		'savePath' => $savepath,
            		'maxSize' => 11048576,
            		'saveName'   =>    array('uniqid',''),
            		'exts'       =>    array('jpg', 'gif', 'png', 'jpeg',"txt",'zip'),
            		'autoSub'    =>    false,
            );
			$upload = new \Think\Upload($config);// 
			$info=$upload->upload();
            //开始上传
            if ($info) {
                //上传成功
                //写入附件数据库信息
                $first=array_shift($info);
                if(!empty($first['url'])){
                	$url=$first['url'];
                }else{
                	$url=C("TMPL_PARSE_STRING.__UPLOAD__").$savepath.$first['savename'];
                }
				
               	$water_img='.'.C("WATER_IMG");
				$water_weizhi=C("WATER_WEIZHI");
				$water=C("WATER");
				$water_url='.'.$url;
				switch ($water_weizhi) {
				  	 case "1":
				     $water_weizhi=\Think\Image::IMAGE_WATER_NORTHWEST;
				     break;
				   	 case "2":
				     $water_weizhi=\Think\Image::IMAGE_WATER_NORTH;
				     break; 
				     case "3":
				     $water_weizhi=\Think\Image::IMAGE_WATER_NORTHEAST;
				     break; 
				     case "4":
				     $water_weizhi=\Think\Image::IMAGE_WATER_WEST;
				     break; 
				     case "5":
				     $water_weizhi=\Think\Image::IMAGE_WATER_CENTER;
				     break; 
				     case "6":
				     $water_weizhi=\Think\Image::IMAGE_WATER_EAST;
				     break; 
				     case "7":
				     $water_weizhi=\Think\Image::IMAGE_WATER_SOUTHWEST;
				     break;
					 case "8":
				     $water_weizhi=\Think\Image::IMAGE_WATER_SOUTH;
				     break;
				     case "9":
				     $water_weizhi=\Think\Image::IMAGE_WATER_SOUTHEAST;
				     break;
				   default:
				     $water_weizhi=\Think\Image::IMAGE_WATER_NORTHWEST;
				}
				if($water==1){
					$image = new \Think\Image(); 
				 	$image->open($water_url)->water($water_img,$water_weizhi)->save($water_url); 
				}
				 
			   
			   
				echo "1," . $url.",".'1,'.$first['name'];
				
				exit;
            } else {
                //上传失败，返回错误
                exit("0," . $upload->getError());
            }
        } else {
            $this->display(':swfupload');
        }
    }

}
